﻿#include "PasswordEdit.h"

namespace GeneralUI {

	PasswordEdit::PasswordEdit(QWidget *parent)
		: QLineEdit(parent)
	{
		init();
	}

	PasswordEdit::~PasswordEdit()
	{
	}

	void PasswordEdit::init()
	{
		//setStyleSheet("QLineEdit {font-family: Microsoft YaHei;font-size: 12px;border: 1px solid #e5e5e5;"
		//	"border-radius: 4px;padding: 2px 2px;min-height: 24px;max-height: 24px;}");
		m_bVisible = false;
		setEchoMode(QLineEdit::Password);
		m_pAction = new QAction(this);
		m_pAction->setIcon(QIcon(":/png/resource/png/no_display.png"));
		addAction(m_pAction, QLineEdit::TrailingPosition);
		connect(m_pAction, &QAction::triggered, this, &PasswordEdit::onInputVisible);
	}

	void PasswordEdit::onInputVisible()
	{
		m_bVisible = !m_bVisible;
		if (m_bVisible)
		{
			m_pAction->setIcon(QIcon(":/png/resource/png/display.png"));
			setEchoMode(QLineEdit::Normal);
		}
		else
		{
			m_pAction->setIcon(QIcon(":/png/resource/png/no_display.png"));
			setEchoMode(QLineEdit::Password);
		}
	}
}
